package com.example.service.impl;

import java.util.List;

import com.example.domain.WarrantyClaimDetailsResult;
import com.example.mapper.WarrantyClaimDetailsResultMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.mapper.WarrantyClaimMapper;
import com.example.domain.WarrantyClaim;
import com.example.service.IWarrantyClaimService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 保修申请Service业务层处理
 * 
 * @author whj
 * @date 2024-09-11
 */
@Service
public class WarrantyClaimServiceImpl implements IWarrantyClaimService 
{
    @Autowired
    private WarrantyClaimMapper warrantyClaimMapper;
    @Autowired
     private WarrantyClaimDetailsResultMapper warrantyClaimDetailsResultMapper;


    /**
     * 查询保修申请
     * 
     * @param id 保修申请主键
     * @return 保修申请
     */
    @Override
    public WarrantyClaim selectWarrantyClaimById(Long id)
    {
        return warrantyClaimMapper.selectWarrantyClaimById(id);
    }

    /**
     * 查询保修申请列表
     * 
     * @param warrantyClaim 保修申请
     * @return 保修申请
     */
    @Override
    public List<WarrantyClaim> selectWarrantyClaimList(WarrantyClaim warrantyClaim)
    {
        return warrantyClaimMapper.selectWarrantyClaimList(warrantyClaim);
    }

    /**
     * 新增保修申请
     * 
     * @param warrantyClaim 保修申请
     * @return 结果
     */
    @Override
    @Transactional
    public int insertWarrantyClaim(WarrantyClaim warrantyClaim)
    {
        int i = warrantyClaimMapper.insertWarrantyClaim(warrantyClaim);
        WarrantyClaimDetailsResult warrantyClaimDetailsResult
                =new WarrantyClaimDetailsResult();
        BeanUtils.copyProperties(warrantyClaim,warrantyClaimDetailsResult);
        int i1 = warrantyClaimDetailsResultMapper.
                insertWarrantyClaimDetailsResult(warrantyClaimDetailsResult);
        if(i>0&&i1>0){
            return 1;
        }else {
            return 0;
        }
    }

    /**
     * 修改保修申请
     * 
     * @param warrantyClaim 保修申请
     * @return 结果
     */
    @Override
    public int updateWarrantyClaim(WarrantyClaim warrantyClaim)
    {
        System.out.println("ser"+warrantyClaim.getContent());
        return warrantyClaimMapper.updateWarrantyClaim(warrantyClaim);
    }

    /**
     * 批量删除保修申请
     * 
     * @param ids 需要删除的保修申请主键
     * @return 结果
     */
    @Override
    public int deleteWarrantyClaimByIds(Long[] ids)
    {
        return warrantyClaimMapper.deleteWarrantyClaimByIds(ids);
    }

    /**
     * 删除保修申请信息
     * 
     * @param id 保修申请主键
     * @return 结果
     */
    @Override
    public int deleteWarrantyClaimById(Long id)
    {
        return warrantyClaimMapper.deleteWarrantyClaimById(id);
    }
}
